package com.sunxu;

import com.sunxu.job.MyJob;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

/**
 * @Author 孙许
 * @Date 2019/12/08 21:27
 * @Description
 */
public class QuartzDemo {
    public static void main(String[] args) throws SchedulerException {
        // 执行器
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
        scheduler.start();
        // 具体的任务
        JobDetail jobDetail = JobBuilder.newJob(MyJob.class)
                .withIdentity("jobDetail", "group1")
                .usingJobData("count", 1)
                .build();
        // 触发器
        Trigger trigger = TriggerBuilder.newTrigger().startNow()
                .withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(10).repeatForever()).build();
        scheduler.scheduleJob(jobDetail, trigger);
        try {
            Thread.sleep(600000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        scheduler.shutdown();
    }
}
